home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Auge 4000 / Auge 4000 #05 (1987-05-15)(Amiga User Gruppe Einzugsgebiet 4000).zip / Auge 4000 #05 (1987-05-15)(Amiga User Gruppe Einzugsgebiet 4000).adf / DBW_Render / ray.doc < prev    next >
Text File  |  1987-05-23  |  48KB  |  926 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *            Copyright (c) 1987, David B. Wecker            *
  4.  *                All Rights Reserved                *
  5.  *                                    *
  6.  * This file is part of DBW_Render                    *
  7.  *                                    *
  8.  * DBW_Render is distributed in the hope that it will be useful, but    *
  9.  * WITHOUT ANY WARRANTY. No author or distributor accepts        *
  10.  * responsibility to anyone for the consequences of using it or for    *
  11.  * whether it serves any particular purpose or works at all, unless    *
  12.  * he says so in writing. Refer to the DBW_Render General Public    *
  13.  * License for full details.                        *
  14.  *                                    *
  15.  * Everyone is granted permission to copy, modify and redistribute    *
  16.  * DBW_Render, but only under the conditions described in the        *
  17.  * DBW_Render General Public License. A copy of this license is        *
  18.  * supposed to have been given to you along with DBW_Render so you    *
  19.  * can know your rights and responsibilities. It should be in a file    *
  20.  * named COPYING. Among other things, the copyright notice and this    *
  21.  * notice must be preserved on all copies.                *
  22.  ************************************************************************/
  23.  
  24.  Sections
  25.  ~~~~~~~~
  26.     Announcement    - announcement of software availability
  27.     Included        - what's in the package
  28.     Under Development    - what's currently being written
  29.     Background Info    - what is this package?
  30.     Running RAY        - how to run the ray tracer
  31.     Running RAY2    - how to run the post-processor
  32.     Running DISPLAY    - how to run the display program
  33.     Creating a .DAT file- what goes into the input file (the hardest part)
  34.     Source file info    - how to rebuild the package
  35.  
  36.  Announcement
  37.  ~~~~~~~~~~~~
  38. If you liked the ray traced images previously distributed... you're
  39. going to LOVE DBW_Render. This package is a FULL re-implementation of the Ray
  40. Tracer that I've been using on VAXen to create all those images.
  41.  
  42. It will run on a standard Amiga (with 512k of memory (and can be configured
  43. to run in 256k if necessary)). By adding AI-heuristics, elapsed time to
  44. compute an image is within the same order of magnitude as a VAX-780 (even
  45. though the Amiga doesn't have hardware floating point or virtual memory)!
  46. For example "glass" computes in 50 hours on an Amiga without the heuristics.
  47. With the heuristics, the image (at full resolution) can be computed in 11 hours.
  48.  
  49.  Included:
  50.  ~~~~~~~~~
  51.     RAY    - ray tracing program
  52.     RAY2    - post processor to create IFF/ILBM format files
  53.     DISPLAY    - general display program for RAY2's output
  54.     *.DAT    - sample input files
  55.     *.TMP    - sample RAY output files
  56.     *.ILBM    - sample HAM encoded pictures (RAY2 output)
  57.     *.c    - all MANX-Aztec C sources for the package
  58.     *.h    - all MANX-Aztec C include files for the package
  59.     RAY.DOC    - full documentation for the package
  60.     COPYING - General License Agreement
  61.  
  62. Please read the General License Agreement (file: COPYING) before proceeding.
  63.  
  64.  Under Development
  65.  ~~~~~ ~~~~~~~~~~~
  66. Depending on the level of interest in this software, I will continue work on: 
  67.  
  68.     DBW_ED3D a full 3-dimensional graphics editor (so you don't have to
  69.          mathematically specify the input file to RAY, you can just
  70.          draw it).
  71.  
  72.     DBW_FILM which creates a film loop of HAM images (so you can create
  73.          your own "juggler" type demos).
  74.  
  75.     ----     a version of the software using increased memory and floating
  76.          point co-processor.
  77.  
  78.     ----     maintenance and enhancements to the current package.
  79.  
  80.  Background Information
  81.  ~~~~~~~~~~ ~~~~~~~~~~~
  82. The DBW_Render package uses an algorithm called Distributed Ray Tracing.
  83. In addition to neatly solving the hidden surface problem, ray tracing
  84. (in general) affords the opportunity for doing excellent (that is,
  85. highly realistic) shading and illumination calculations.
  86.  
  87. This package is written in MANX-Aztec C and runs on any AMIGA system. The
  88. RAY program knows how to create images composed of four primitive
  89. geometric objects: spheres, parallelograms, triangles, and flat circular
  90. rings (disks with holes in them). Some of the features of the program
  91. are:
  92.  
  93.     Determination of correct shadows cast by arbitrarily shaped objects,
  94.     onto arbitrarily shaped objects, due to arbitrarily placed light
  95.     sources.
  96.  
  97.     Diffuse and specular reflections (with arbitrary levels of gloss or
  98.     polish).  Rudimentary modeling of object-to-object diffusely reflected
  99.     light is also implemented, that among other things accurately simulates
  100.     color bleed effects from adjacent contrasting colored objects.
  101.  
  102.     Mirror reflections, including varying levels of mirror smoothness
  103.     or perfection.
  104.  
  105.     Refraction and translucency (which is akin to variable microscopic
  106.     smoothness, like the surface of etched glass).
  107.  
  108.     Two types of light sources: purely directional (parallel rays from
  109.     infinity) of constant intensity, and spherical sources (like light
  110.     bulbs, which cast penumbral shadows as a function of radius and
  111.     distance) where intensity is determined by the inverse square law.
  112.  
  113.     Photographic depth-of-field.  That is, the virtual camera may be
  114.     focused on a particular object in the scene, and the virtual
  115.     camera's aperture can be manipulated to affect the sharpness of
  116.     foreground and background objects.
  117.  
  118.     Solid texturing.  Normally, a particular object (say a sphere) is
  119.     considered to have constant properties (like color) over the entire
  120.     surface of the object, often resulting in fake looking objects.
  121.     Solid texturing is a way to algorithmically change the surface
  122.     properties of an object (thus the entire surface area is no longer of
  123.     constant nature) to try and model some real world material.
  124.     Currently the program has built in rules for modelling wood, marble,
  125.     bricks, snow covered scenes, water (with arbitrary wave sources),
  126.     plus more abstract things like color blend functions.
  127.  
  128.     Fractals.  The program implements what's known as recursive triangle
  129.     subdivision, which creates all manners of natural looking surface
  130.     shapes (like broken rock, mountains, etc.).  The character of the
  131.     fractal surface (degree of detail, roughness, etc.) is controlled by
  132.     parameters fed to the program.
  133.  
  134.     AI heuristics to complete computation of a scene within a user
  135.     specified length of time.
  136.  
  137. When the RAY program runs, it reads a sort of command file, that contains a
  138. geometric description of the scene to be rendered, plus desired global lighting
  139. conditions, camera parameters, etc.  Then the program computes for a long
  140. time, writing each scan line to disk as it computes it. The format of a
  141. scanline (in the .TMP) file is:
  142.  
  143.     <line  number>    -   2 bytes long
  144.     <red   pixels>    - 160 bytes long (4 bits per pixel)
  145.     <green pixels>    - 160 bytes long
  146.     <blue  pixels>  - 160 bytes long
  147.  
  148. For an entire screen (400 scan lines) this file is 192,800 bytes. A second
  149. program is run (RAY2) to obtain one of three possible output files:
  150.  
  151.     4096 colors (HAM) encoded interlaced 320x400 resolution
  152.       32 colors               interlaced 320x400 resolution
  153.       32 colors                          320x200 resolution
  154.  
  155. All of the file formats are standard IFF/ILBM and may be displayed by the
  156. supplied DISPLAY program. In addition, the last version (320x200) may be
  157. edited by any standard graphic package (e.g., DPaint). Others may be
  158. able to handle the more complex first two.
  159.  
  160. In all, the DBW_Render package represents about 4000 lines of C code. 
  161. It is largely based on original algorithms for the VAX by Tom Dahl and
  162. Tone Engel at Digital Equipment Corporation. The AMIGA version has taken
  163. several months to create.
  164.  
  165.  Runningõ¡ RAY
  166.  ~~~~~~~ ~~~
  167.  
  168. REMINDER:    BEFORE RUNNING ANYTHING MAKE SURE YOU BACKUP THIS DISK!!!
  169.  
  170. Once you have an input file (described below in the "Creating a .DAT file"
  171. section) you can run the ray tracer. Remember that the output of the
  172. Ray Tracer (for a full screen) will be 192,800 bytes or a little over
  173. 400 blocks so make sure you have enough free space on the disk you are
  174. running on. It is NOT suggested that you direct the output to RAM: since
  175. if the machine crashes you will lose all of your work. In addition make
  176. sure you have a STACK of at least 10000 before you start!
  177.  
  178. If you have a file called GLASS.DAT for input, you can type:
  179.  
  180.     1> ray glass
  181.  
  182. The program will start running. All of the options are in the .DAT file.
  183. See the file GLASS.DAT (distributed with the package) for an example.
  184. As the program runs, it will write to the file GLASS.TMP. If you want
  185. different names for the input and output files, then run the program with
  186. no parameters:
  187.  
  188.     1> ray
  189.  
  190. at which point you will be prompted for the input file:
  191.  
  192.     Scene description file?
  193.  
  194. to which you could answer GLASS.DAT. The program will then ask for the
  195. name of the output file:
  196.  
  197.     File name to save picture (.tmp)?
  198.  
  199. to which you could answer DF1:GLASS.TMP.
  200.  
  201. The program will now compute the picture. Note that 4 extra scan lines
  202. before and after your scene are ALWAYS computed, so if you told the program
  203. to do a full screen (command "& 0 400" in the command file) you will notice
  204. that the program will start at scan line -4 and will and at scan line 403.
  205. This is due to one requirement of the AI-heuristics to fill a scan line cache
  206. before output can occur.
  207.  
  208. When the program finishes, it will give you a bunch of statistics about
  209. the picture. One of the most interesting is the number of pixels GUESSED as
  210. opposed to the number of pixels COMPUTED. This will give you and idea of how
  211. high a quality output to expect (0 guessed = perfect). These numbers are
  212. affected by the amount of time you give the program to compute the
  213. picture in ("R" command in the command file).
  214.  
  215.  Running RAY2
  216.  ~~~~~~~ ~~~~
  217. After RAY has completed, the output .TMP file (or files) may be post-processed
  218. by RAY2. Multiple files may be given to RAY2 for several reasons:
  219.  
  220.     1) The machine crashed and so you have one partial file and another
  221.        that has the rest of the scan lines in it.
  222.  
  223.     2) You decided to do the picture in strips and have a seperate file
  224.        for each strip.
  225.  
  226.     3) You did the entire picture, but there are blurry scan lines around
  227.        complex objects (like light sources) because you didn't give it
  228.        enough time... so you recomputed the bad sections allowing more
  229.        time.
  230.  
  231. These will become clearer as we do the examples. To run the program, type:
  232.  
  233.     1> ray2 glass
  234.  
  235. this will open file GLASS.TMP (which was output from RAY), scan the file
  236. finding the most used colors, open a custom screen, create a HAM mode image
  237. on the screen and will then read back the image from the screen creating
  238. GLASS.ILBM. When the program is done, it will flash the screen at which point
  239. you can hit the (invisible) close gadget in the upper left corner to exit
  240. the program.
  241.  
  242. While the program is creating the output file, it will complement the first
  243. pixel on each scan line it computes so that you can see its progress through
  244. the picture.
  245.  
  246. An example of using ALL options for the RAY2 program is:
  247.  
  248.     1> ray2 -c 1 -h 1 -l 1 -o glass.ilbm glass
  249.  
  250. Where the options are:
  251.  
  252.     -c     = is compression allowed  (0 or 1) (default = yes = 1)
  253.     -h     = is HAM mode to be used  (0 or 1) (default = yes = 1)
  254.     -l     = is LACE mode to be used (0 or 1) (default = yes = 1)
  255.     -o     = name of the output file to create
  256.     <name>    = upto 10 input file names
  257.  
  258. The example shown will create an image exactly like the previous example
  259. (since all defaults are being taken). If we wanted the simplest picture
  260. (that something like DPaint could edit) and we had several input files,
  261. we could type:
  262.  
  263.     1> ray2 -h 0 -l 0 -o glass.pic glass1 glass2 glass
  264.  
  265. In this example we are using multiple input files. The program will ALWAYS
  266. use scanlines from files earlier in the command line (if possible). So for
  267. example, GLASS.TMP (on the distribution disk) contains a 12 hour complete
  268. picture. GLASS1.TMP and GLASS2.TMP contain scanlines around the light sources
  269. (that are blurry in GLASS.TMP) but with a resolution of 24 hours (so that
  270. they're much better (each took between 1 and 2 hours to compute)).
  271.  
  272. This program also uses a heuristic to figure out how to fold 4096 colors
  273. into 32 when you turn HAM mode off.
  274.  
  275.  Running DISPLAY
  276.  ~~~~~~~ ~~~~~~~
  277. DISPLAY is a VERY simple program to run, all you need to say is:
  278.  
  279.     1> display glass
  280.  
  281. and GLASS.ILBM will get displayed. If you have a different extension, then
  282. type the full file name:
  283.  
  284.     1> display glass.pic
  285.  
  286. The picture will be displayed until you click the mouse on the invisible close
  287. gadget in the upper left corner of the screen. Remember that you can use
  288. Left-Amiga-N and Left-Amiga-M to push this screen behind the Workbench and
  289. pull it back in front.
  290.  
  291.  Creating a .DAT file
  292.  ~~~~~~~~ ~ ~~~~ ~~~~
  293. Okay, now the hard part: the contents of the script input file.  The
  294. file is a standard ASCII text file, with each line forming a separate
  295. object or command to RAY.  The lines begin with a command character
  296. (which is CASE SENSITIVE).  The command characters are:
  297.  
  298. R   Set resolution (optional, if missing, program will default to 12.0 hours)
  299. N   Global index of refraction (optional, default = 1.0)
  300. Z   Produce 2D histogram, rather than true image (default true image)
  301. a   Set overriding ambient proportion factor (default not overridden)
  302. A   Set antialiasing parameters (default no antialiasing)
  303. F   Set lens focus and aperture for depth of field (default infinite depth)
  304. M   Set global diffuse lighting parameters (default off)
  305. &   Define scan-line region of image to generate
  306. *,! comment, ignored
  307. b   Set background color
  308. w   Define a wave source
  309. g   Define a color blend texture
  310. n   Define a snowfall texture
  311. k   Define a 3D checkerboard texture
  312. H   Set global haze parameters (default no haze)
  313. f   Define fractal surface parameters
  314. m   Define a marble texture
  315. d   Define a wood texture
  316. e   Set the eye (camera) view parameters
  317. l   Define a directional light source
  318. L   Define a spherical light source
  319. {   Start an extent
  320. }   Terminate an extent
  321. s   Specify a spherical object
  322. t   Specify a planar triangular object
  323. x   Specify a fractal triangular object
  324. q   Specify a planar paralleligram object
  325. r   Specify a planar ring (annular) object
  326.  
  327. First, all color values consist of three numbers that range from 0 to 1.
  328. The color components are specified BLUE, GREEN, RED.
  329.  
  330. All position/direction values are three numbers ranging in whatever numbering
  331. system you want.  The numbers are X, Y, Z order.  Assuming you are
  332. looking into the screen in the negative Z direction, positive X is to
  333. the right, positive Y is up, and positive Z is out from the screen.
  334.  
  335. Okay, on to the specifics of the parameters that each command character
  336. requires.  First are listed all the general (environmental) commands, then are
  337. listed the commands that create objects to be rendered in the scene.
  338.  
  339.         Global index of refraction (optional, default = 1.0)
  340. N INDEX
  341.     This single value is taken to be the index of refraction of "the
  342.     air", or put another way of the space between and outside of all
  343.     objects.
  344.  
  345.         Set resolution (optional, default = 12.0 hours)
  346. R RESOLUTION
  347.     The RESOLUTION value controls the MAXIMUM amount of time that a full
  348.     screen (400 scanlines) is allowed to take. This number should typically
  349.     be between 1.0 and 30.0 hours. The more time you give the program the
  350.     better the picture will be that you get.
  351.  
  352.         Produce 2D histogram, rather than true image
  353. Z FLAG
  354.     Normally, the contents of the .TMP file that the ray tracer produces
  355.     is a binary pixel version of the described scene.  However, for the
  356.     purposes of doing performance tuning of an antialiased scene, you can
  357.     include the command "Z 1" in the script file.  If done, the image file
  358.     that the ray tracer generates will not be the color scene that it normally
  359.     is, but instead will be a sort of 2D histogram of how much computation
  360.     each pixel in the scene consumed, displayed as a gray scale (the brighter
  361.     the pixel, the more computation).  Note that this command is only
  362.     meaningfull if non-default values for the "A" command have been used.
  363.     By default, basically an equal amount of time is spent on each pixel,
  364.     (thus an image with Z set to 1 would come out a flat gray) but the "A"
  365.     command tells the ray tracer to concentrate on certain types of details
  366.     in the scene to produce alias-free images.  Using the Z command with
  367.     a parameter of 1 will allow you to see just where the ray tracer decided
  368.     to spend more time, smoothing edges, etc.
  369.  
  370.         Set overriding ambient proportion factor
  371. a FACTOR
  372.     As described below, each object in the scene contains parameters that
  373.     control how bright the object appears if no light is shining on it.  Thus
  374.     you can set some objects to appear brigher when in shadow that other
  375.     objects.  As an alternative, you can specify the "a" command with a
  376.     parameter from 0 to 1, and this will cause the ambient color of all
  377.     objects in the scene to be a fraction of their diffuse brightness.
  378.     When the "a" command is used, the BGR ambient values for each object are
  379.     ignored (but they must still be specified).  A reasonable starting point
  380.     would be to set FACTOR from between .1 and .2.
  381.  
  382.         Set antialiasing parameters
  383. A COUNT THRESHHOLD
  384.     By default, the ray tracer computes one ray into the scene for each pixel
  385.     in the image (so a 320X4000 image computes ~128K rays).  Quite often, some
  386.     unpleasant side effects of the digital generation process become apparent
  387.     in a scene generated with one ray per pixel, for example diagonal lines
  388.     are rendered as a sequence of discrete stairsteps -- the dreaded jaggies.
  389.     Such false features are called aliasing defects.  There are numerous
  390.     techniques devised to try to reduce the magnitude of these defects,
  391.     collectively referred to as the process of anti-aliasing.  (There are many
  392.     other types of aliasing defects besides jaggies.  An example of another
  393.     "defect" is the razor-sharp shadows that are traditionally found in
  394.     computer generated imagery -- real-world shadows are always at least a
  395.     teensy bit diffuse.)
  396.  
  397.     The COUNT parameter determines how many rays will be traced for each pixel
  398.     in the scene -- the more, the better, but the slower the computing.  A good
  399.     starting value is 4.  What happens is that a bunch of rays (e.g. 4) are
  400.     sent into the pixel cone at random -- they are "distributed" across the
  401.     horizontal and vertical dimensions.  Thus, this ray tracer is said to
  402.     implement Distributed Ray Tracing.
  403.  
  404.     The THRESHHOLD value relates to a rather complicated feature in the ray
  405.     tracer called Statistically Optimized Distributed Ray Tracing.  The way
  406.     this works is that the program computes the intensities of the bunch of
  407.     rays that are distributed into the pixel.  In this example, say there are
  408.     four rays in the bunch.  The program computes the statistical variance of
  409.     the four resulting intensities.  If the variance is small, the odds are
  410.     that the portion of the scene being imaged is a smooth patch.
  411.     Thus a good approximation to the ideal intensity of that pixel has been
  412.     computed.  But let's say that the pixel happens to fall on a diagonal edge.
  413.     Some of the distributed rays will be cast to one side of the edge, and some
  414.     of them to the other.  Thus the variance will be high.  The program looks
  415.     at this, and if the variance is past the THRESHHOLD value, will distribute
  416.     another group of (in this case) four rays into the pixel.  Then the variance
  417.     of the eight rays will be examined, and the process repeated until the
  418.     required smoothness has been reached (or some arbitrarily large number of
  419.     rays have been cast, and the process halts).  Setting THRESHHOLD to values
  420.     of 1.0 or higher generally will force no extra groups of rays to be cast,
  421.     beyond the initial group of COUNT rays.  Meaningfull values of THRESHHOLD
  422.     generally fall in the .0001 to .1 range.
  423.  
  424.         Set lens focus and aperture for depth of field
  425. F APERTURE FOCUS
  426.     This command is optional; if omitted, the scene will be rendered such
  427.     that all objects will be in perfect focus (a pin-hole camera effect).
  428.     With this command, you can add depth-of-field effects to a scene (though
  429.     at great computation speed degradation, as described below).
  430.     The APERTURE parameter specifies the radius of the hypothetical lens
  431.     in the camera that is taking the picture of the scene.  FOCUS sets the
  432.     distance from the camera (or eye) at which objects will appear in perfect
  433.     focus.  The magnitude of both values depends upon the coordinate system
  434.     in use by your scene, of course, but here is an example for determining a
  435.     reasonable camera aperture.  Say that one unit of distance represents an
  436.     inch.  Assume you set the focus distance to 100 inches; with this scale,
  437.     a reasonable value for aperture is 0.5 to 2.0.
  438.  
  439.     In order to achieve a good quality smooth blurring of the foreground and
  440.     background, you will need to set the antialiasing parameters up from their
  441.     defaults (with the A command).  A good start would be 20 to 30 rays per
  442.     pixel; the THRESHHOLD value doesn't matter much; it could be set to 1.
  443.  
  444.         Set global diffuse lighting parameters
  445. M COUNT NUMERATOR DENOMINATOR
  446.     This command relates to the realistic propagation of light as it reflects
  447.     from object to object in the scene.  Traditionally, computer lighting
  448.     models operate such that if an object is directly visible from a light
  449.     source, then the surface of the object is colored according to the
  450.     material's properties, the color and strength of the light, etc.  For
  451.     those objects or portions of objects that are not in the path of a light
  452.     source (aka are in shadow), they are rendered black.  Well, this is
  453.     usually artificial looking, and so a constant dim color is assigned to
  454.     areas in shadow.  (In fact, this program has provisions for this as well,
  455.     the ambient parameters of each object, plus the "a" command.)
  456.  
  457.     But in reality, shadows are filled in with light bounced off walls, etc.
  458.     The M command can be employed to model this diffuse propagation of light
  459.     from object to object.  (Sadly, once again performance suffers
  460.     significantly if you choose to do this, since a great deal of information
  461.     about the scene needs to be collected and analyzed to determine how the
  462.     shadow fill-in should occur.)  How this program does this is to, for each
  463.     pixel, sample extra rays from the surface being rendered, out into the
  464.     scene in random directions to see what other nearby surfaces are acting
  465.     as reflectors, etc.  The COUNT parameter controls how many samples to
  466.     take per pixel; values from 10 on up are okay, but 100 or more are needed
  467.     to render smooth color bleeding from surface to surface, etc.
  468.     The NUMERATOR and DENOMINATOR derive from the recursive nature of the
  469.     ray tracing process: in the process of calculating a ray on the surface
  470.     being rendered, assume the ray strikes an adjacent surface.  Well, from
  471.     THAT surface, another COUNT set of rays will ne sampled, to determine
  472.     ITS color, etc.; thus the process exponentially generates rays that need
  473.     to be computed.  To avoid this recursive growth, the number of sample rays
  474.     that are done per recursion level is scaled from the initial COUNT value,
  475.     according to the supplied NUMERATOR and DENOMINATOR values.   For example
  476.     values of 1 and 2 respectively will reduce by half the number of samples
  477.     taken at each recursion level.  Normally, even this is not a fast enough
  478.     decay, so 1/3 or 1/4 is better, without much noticable loss in resulting
  479.     color fidelity.  In fact, setting NUMERATOR to 0 is not unreasonable.
  480.  
  481.         Define scan-line region of image to generate
  482. & FIRST LAST
  483.     If this command is omitted, the entire image bitmap will be calculated
  484.     (all 400 scan lines).   This command tells the program only to produce
  485.     those scans from FIRST to LAST-1 inclusive.  Once done, the resulting
  486.     fragment images can be combined into one whole image file.   In this way,
  487.     a particularly complex scene may be distributed into a number of CPUs,
  488.     resulting in shorter elapsed generation time. Picture merging is
  489.     accomplished by RAY2).
  490.  
  491.         Set background color
  492. b BLUE GREEN RED
  493.     The simple color value that will be displayed if no objects are
  494.     visible at a given point in the scene.
  495.  
  496.         Define a wave source
  497. w CENTERX CENTERY CENTERZ  WAVELENGTH AMPLITUDE DAMP PROPAGATE
  498.     A number of features in the program use wave sources as a basis for
  499.     calculating various effects (most notably the production of rippled
  500.     surfaces, such as water).  You can define up to 100 wave sources per
  501.     scene.  There is only one "wave source table" stored by the program;
  502.     all of the features that use waves use the same waves.
  503.     The first three values specify the coordinate from which the concentric
  504.     wave fronts emanate from.  WAVELENGTH sets the crest-to-crest distance
  505.     for the wave.  The AMPLITUDE value determines, in an abstract manner,
  506.     the height of the wave at the origin.  The height is not specified in
  507.     normal distance units; rather it is a fixed scale frational value, in the
  508.     approximate range of 0.1 (small, flat waves) to 0.5 (strong waves).
  509.     The DAMP value controls the damping of successive trains of waves.  The
  510.     value 1.0 means no damping; the waves will contine out to infinity from
  511.     the source.  Value 0.7 means that successive crests will be 70% the height
  512.     of the preceeding crest.  The PROPAGATE value controls what phase the
  513.     wave starts broadcasting at; the value ranges from 0.0 (starting at a
  514.     crest at the origin) through 0.5 (180 degrees out of phase -- a trough)
  515.     and back to 1.0 (a crest).  This can be used in sequenced frames to
  516.     produce moving waves.
  517.  
  518.         Define a color blend texture
  519. g BCOLOR GCOLOR RCOLOR  START RANGE
  520.     Normally, an object is solidly and uniformly colored across its entire
  521.     surface.  This command lets you define a blend function which can be
  522.     applied to any object, in such a manner that the color of the object
  523.     will vary as a function of altitude (Y coordinate).  For example, a
  524.     sphere could be blue at the south pole, and yellow at the north pole,
  525.     with the color smoothly changing in the middle.
  526.     You can define up to ten blends per scene.
  527.     The three COLOR values specify the target color that the surface will
  528.     blend to with increasing Y coordinate (the initial color of the object
  529.     at low Y coordinate values is taken from the diffuse coeficients of
  530.     the object, as defined a ways below in the section on object properties).
  531.     The START value defines the low-Y coordinate where blending starts;
  532.     surface points below this Y level will be colored with the objects
  533.     diffuse coeficients.  The blending continues from START, continuing for
  534.     RANGE units upward.  At the level of START+RANGE, the blend would have
  535.     saturated out at the new COLOR value.  Points above START+RANGE will
  536.     maintain the new COLOR.  As an example, consider a sphere of radius
  537.     100 units positioned at the origin.  If START was set to -33, and RANGE
  538.     was set to 66, the result would be that the lower third of the sphere
  539.     would be its base diffuse color; the middle third would gradually change
  540.     color up until at the +33 level the color would attain the new COLOR;
  541.     the upper third of the sphere would maintain the new COLOR.
  542.  
  543.         Define a snowfall texture
  544. n START ALTITUDERANGE ALTFACTOR THRESHHOLD
  545.     This texture function is similar to the above blend texture.  It is
  546.     still under development.  This is intended to be used with the fratcal
  547.     surface capabilities described below.  The theory is that this will
  548.     distribute snow onto an object, the nature of which varies according to
  549.     the local surface slope and altitude.
  550.     START is the lower bound below which there can be no snowfall
  551.     accumulation, even on level surfaces.  Points on the surface above the
  552.     level of START+ALTITUDERANGE generally are solidly blanketed with snow.
  553.     ALTFACTOR is a scaler that lets you determine how important altitude is
  554.     in determining snow cover; value 0 means it is irrelevant (thus it is just
  555.     a function of local surface slope).  Values above 1.0 generally result
  556.     in a faster buildup of snow at the low end of the ALTITUDERANGE scale.
  557.     THRESHHOLD controls when a surface will be solidly blanketed, if it
  558.     meets the threshhold test.  Values for this parameter range from 0.0
  559.     (at which everything from START and above will be solidly coated,
  560.     regardless of slope) to 1.0, where coverage will be a continuous function
  561.     of slope and altitude.  Values around .4 result in surfaces from about
  562.     40 degrees of slope and flatter to be solidly covered.
  563.  
  564.         Define a 3D checkerboard texture
  565. k BCOLOR GCOLOR RCOLOR  X Y Z  JUNK1 JUNK2 JUNK3
  566.     You can define up to 10 checker textures per scene.
  567.     This texture function determines the color of points on the surface of
  568.     an object, using a 1- (layer), 2- (checker, column), or 3-dimensional
  569.     (block) model.  As the points on the surface of an object are colored,
  570.     this texture function can be used to determine whether the color of the
  571.     point in question is the object's base diffuse color, or is a different
  572.     specified color (controlled the three COLOR parameters to this command).
  573.     To determine whether the surface point is inside or outside which color
  574.     region, the X Y Z pattern size values are checked.  The X parameter
  575.     defines the width of successive layers from left to right; Y defines the
  576.     width of successive layers from top to bottom; Z is for front to back.
  577.     Note that one or more X Y or Z values can be set to 0.  This will cancel
  578.     any variation in the pattern in the corresponding dimention.  For example,
  579.     if X and Z are set to 10 but Y is 0, the effect will be of square vertical
  580.     columns of alternating color.  If only Y were non-zero, the effect would
  581.     be of horizontal layers of alternating color.  Setting all three to non-
  582.     zero creates a solid 3D block pattern.  The width of the layers in X Y
  583.     and Z need not be the same (so you can make long flat blocks, for
  584.     example).
  585.     JUNK1, JUNK2, and JUNK3 are currently not used and should be set to 0.
  586.  
  587.         Set global haze parameters
  588. H BCOLOR GCOLOR RCOLOR  DISTANCE
  589.     If this command is omitted, the color of each pixel in the scene is not
  590.     affected by how far the rendered surface is from the eyepoint.  By using
  591.     this haze command, you can cause objects in the distance to be
  592.     progressively tinted to a specified target haze color (the three COLOR
  593.     values).  Objects that are DISTANCE units or farther from the eyepoint
  594.     will be completely tinted or blended to the haze color and thus will
  595.     become effectively invisible.  Objects closer than this distance will be
  596.     continuously tinted from their true local color to the haze color, in
  597.     a linear manner as a function of distance.
  598.  
  599.         Define fractal surface parameters
  600. f RECURSIONLEVEL  XSCALE YSCALE ZSCALE  FINALTEXTURE
  601.     This texture can only be applied to 'x' objects as defined below.
  602.     The ray tracer so far only knows how to render a small set of primitive
  603.     object shapes, one of which is the three-sided polygon (triangle).
  604.     As described in the 'x' command below, the ray tracer does have the
  605.     capability to algorithmically generate compound objects that are
  606.     constructed out of large numbers of adjacent triangles forming what
  607.     is called a stochastic surface (often thought of as a fractal surface,
  608.     though in fact the relationship to the mathemacits of fractals is
  609.     limited).  This command defines parameters that the ray tracer uses in
  610.     constructing the mesh of triangular surface patches.
  611.  
  612.     You can define up to 10 fractal textures per scene.  In order to define
  613.     a fractal surface, you must also define at least one wave source with
  614.     the "w" command (the reason for this apparently unrelated need will be
  615.     explained).  The general fractal construction procedure is based on
  616.     recursive triangle subdivision, applying complex coordinate shifts when
  617.     determining the vertices of the subdivision triangles.  You start with
  618.     one master triangle that controls the gross size and orientation of the
  619.     final surface.  The original triangle is split into four triangles (by
  620.     bisecting the three sides and connecting the midpoints).  The corners of
  621.     the new triangles are then shifted in space, and they are recursively
  622.     subdivided in turn, to the desired level.  The RECUSIONLEVEL sets this
  623.     depth; the higher the depth, the finer the resulting surface, but the
  624.     slower the image will take to compute (on the order of four times with
  625.     each successive level).  Plus larger level values require substantial
  626.     quantities of address space to contain the generated triangle data (on
  627.     the order of thousands of 512-byte memory pages for a level of 7,
  628.     for example... so BE CAREFUL!).
  629.  
  630.     The X Y and ZSCALE values allow you to emphasize distortion differenly in
  631.     the three dimensions (X and Z of 1.0, with Y of 3.0 results in three times
  632.     as much vertical relief as horizontal, for example).  Values of 0 for
  633.     a scale parameter cause the sub-triangles to not move in the indicated
  634.     dimension (X and Y of 0 will make the resulting surface maintain a
  635.     triangular silhouette as seen from above).
  636.  
  637.     The FINALTEXTURE value will be assigned as the texture function number
  638.     for each of the sub-triangles (see the description of texture function
  639.     values for objects below).  Basically, this allows you to apply a uniform
  640.     texture to the entire fractal object: a smooth color gradiation, a
  641.     checkerboard, etc.
  642.  
  643.     As mentioned above, to get a good rough fractal surface, you need to
  644.     also define a small number of wave sources.  A good starting point is
  645.     to specify five or six wave sources, whose actual XYZ coordinates are
  646.     scattered about the scene.  Giving them different wavelenghts and
  647.     amplitudes will increase the fluctuation in the surface.  Generally,
  648.     the damping should be small (values of or near 1.0).  The actual manner
  649.     in which the waves are utilized in constructing the sub triangle vertices
  650.     is beyond convenient description; suffice it to say that there is NO
  651.     randomness involved, and that different wave patters will produce
  652.     markedly different fractal surfaces.  Experment.
  653.  
  654.         Define a marble texture
  655. m BVEINCOLOR GVEINCOLOR RVEINCOLOR XSCALE TURBULENCE SQUEEZE
  656.     You can define up to ten marble textures per scene.  This texture
  657.     relies on your having defined at least one wave source, for reasons
  658.     described below.
  659.  
  660.     The marble is modelled as a base substance that has intrusions of a second
  661.     substance into the base.  The base color is determined by the diffuse
  662.     coefficients for the object.  The intrusion color is specified in the three
  663.     VEINCOLOR parameters.  The actual color for the surface of the marble
  664.     object is a complex blending function of the two starting colors.
  665.  
  666.     The basic formula for making the intrusions (veins) is to start with
  667.     equally spaced vertical layers (spaced along the X axis).  The spacing is
  668.     determined by the XSCALE parameter (good values are from 0.1 to 1).  Then
  669.     turbulence is applied to the layers, deforming them into myriad whorls and
  670.     streaks, etc.  The amount of turbulence is set by the TURBULENCE parameter
  671.     (values from 1.0 to 3.0 are nice).  The rough thickness of the streaks is
  672.     determined by the SQUEEZE parameter (which must be an integer -- no
  673.     fractional component).  The value 1 means leave them normal width; 2 means
  674.     twice as thin; 3 means four times as thin; 4 means eight times, etc.
  675.     Another way to think of SQUEEZE is that it affects how fast the blending
  676.     occurs from the base to the vein color.
  677.  
  678.     The turbulence is controlled by (of all things) the wave sources that you
  679.     have defined in the scene.  Unfortunately, the correspondence between a
  680.     particular wave source and a particular turbulent result is almost
  681.     impossible to predict (but it IS possible; there is no randomness
  682.     involved).  All that can really be done is to give guidelines for general
  683.     wave parameter values.  First, four or five wave sources are needed.  The
  684.     wave centers should be well distributed around the scene.  The wavelengths
  685.     should vary amongst the source a good amount (some should be five or six
  686.     times the wavelength of other sources).  Not much damping should be applied
  687.     (values from 1.0 down to 0.95 perhaps).
  688.  
  689.         Define a wood texture
  690. d BCOLOR GCOLOR RCOLOR THICKSCALE RINGSCALE TURBULENCE SQUEEZE
  691.     You can define up to ten wood textures per scene.  This texture
  692.     relies on your having defined at least one wave source, just like for
  693.     the marble textures listed above.  In fact, at this time wood is modelled
  694.     very similarly to marble, except that where marble consists of parallel
  695.     layers of base material, wood consists of concentric cylinders of base
  696.     material (aligned along the Y axis).  The RINGSCALE parameter is
  697.     analogous to XSCALE for marble; TURBULENCE and SQUEEZE are the same.
  698.     THICKSCALE basically controls how faint or strong the grain is rendered;
  699.     values above 1.0 enhance the grain; values less than 1.0 subdue the grain.
  700.  
  701.  
  702.         Set the eye (camera) view parameters
  703. e XPOS YPOS ZPOS  XVIEW YVIEW ZVIEW  XUP YUP ZUP
  704.     First triple sets the position of the eyepoint.  Second triple
  705.     defines the direction (relative to that point) that the eye will
  706.     look along to define what is visible.  The length of this vector
  707.     determines the "wide-andle vs. telephoto" effect.  To guage what
  708.     different lengths mean, at the tip of the VIEW vector the screen is
  709.     projected as if it were 256 units horizontally by 170 units
  710.     vertically.  Thus the magnitude of the numbers you choose for XYZ
  711.     points interact with the view vector length to determine the cone
  712.     of visibility.  The third triple is the direction you want to be
  713.     "up"; usually 0 1 0 is what you want.
  714.  
  715.         Define a directional light source
  716. l BLUE GREEN RED  XDIR YDIR ZDIR
  717.     The first triple is the color and intesity of the light (1 1 1 would
  718.     be bright white; 0.5 0 0.5 would be dim magenta).  The second triple
  719.     is the direction from which the light is comming.  For example 1 0 0
  720.     would mean the light is comming in straight along the X axis (from
  721.     positive to negative).  You can have at most 100 light sources per
  722.     scene (many light sources sloooows things down -- two is
  723.     reasonable!).
  724.  
  725.         Define a spherical light source
  726. l BLUE GREEN RED  XCENTER YCENTER ZCENTER  DISTANCESCALE  RADIUS
  727.     The first triple is the color and base intensity of the light, just as
  728.     for directional light sources.  The second triple is the XYZ coordionate
  729.     of the center of the spherical light source; it can be anywhere inside
  730.     or outside of the visible scene.  (Note that if the center is within the
  731.     scene, it is not a visible object per-se.  For example, if you wanted a
  732.     lightbulb, you would place the spherical light source where you wanted
  733.     it, and also place a transparent sphere at the same coordinates and with
  734.     the same radius.)  The DISTANCESCALE relates to the inverse-square law
  735.     with which the brightness of the light diminishes within the scene.  To
  736.     explain how to set a value for DISTSCALE, consider the following example.
  737.     Say you wanted a full-intensity white lightbulb (i.e. its nominal BGR
  738.     values would be 1 1 1) to shine onto a table.  If the table were, say,
  739.     37 units of distance from the light coordinate, then you'd want to set
  740.     DISTSCALE to 37 in order that the table would be fully illuminated.  Thus,
  741.     objects closer to the light that 37 would appear very bright (indeed,
  742.     probably "overexposed") while objects farther than 37 units from the light
  743.     would become increasingly dimly lit.  RADIUS is the radius of the light
  744.     emitting sphere; 0.0 would be a point light source.  (Note that point
  745.     light sources are faster to compute.)  Also note that non-zero radius
  746.     light sources cast penumbral shadows, though to be effective you will
  747.     need to increase the antialias parameters defined by the "A" command.
  748.  
  749. Now for the actual objects that compose a scene.  You can about thousand
  750. objects max per scene.  All objects have the same basic properties available
  751. to them.  Specifically, the first portion of the command line for any
  752. object starts with:
  753.  
  754. @ TEX FUZZ MIRROR IDX  TRA_B TRA_G TRA_R  AMB_B AMB_G AMB_R  DIF_B DIF_G DIF_R
  755.     "@" is the object command character (s,q,x,t,r).
  756.  
  757.     TEX is an integer value that specified what texture function should be
  758.     applied to this object.  Value 0 means no texture (plain, boring evenly
  759.     colored flat surface).  Positive values select from among the supported
  760.     texture functions, as follows:
  761.  
  762.     Value    Texture function
  763.     -----    ----------------
  764.     1:     Y axis color gradiation
  765.         Compute the color at each point on the surface as a function
  766.         of the point's Y coordinate.  Starting at Y=0, the color
  767.         belnds from red to blue to green and back to red at Y=20.
  768.         The colors repeat evern 20 units in Y.
  769.  
  770.     3:     Mottled diffuse
  771.         The brightness of the surface of the object varies to
  772.         form a mottled pattern.  This texture requires some wave
  773.         sources to be defined.
  774.  
  775.     4:    Wavy surface
  776.         The surface will be rendered as being criss-crossed by
  777.         overlapping waves.  If reflectivity is turned on for the
  778.         object, the reflections will be rippled, etc.
  779.  
  780.     5:    Brick pattern
  781.         The object will be rendered as if it were carved out of
  782.         bricks.  The brick size is currently hardwired to be
  783.         height=3.0, width=8.0, depth=4.0, mortar thickness=0.5.
  784.         The color of the bricks is determined by the diffuse
  785.         coefficients for the object; the color of the mortar is
  786.         hardwired at BLUE=0.8, GREEN=0.85, RED=0.99.  The bricks are
  787.         aligned with the coordinate system.
  788.  
  789.     10..19:    Single Wave
  790.         This is like texture 4, except that the surface is rippled
  791.         by only one wave (rather than all of them with texture 4).
  792.         Texture 10 means use the first wave, texture 11 means use
  793.         the second wave, etc. up to 19 for the tenth wave.
  794.  
  795.     20..29:    Marble
  796.         Render the object as if it were carved out of marble.  The
  797.         marble texture chosen depends on the texture number: texture
  798.         20 uses the first marble defined, texture 21 uses the second
  799.         marble defined, etc.
  800.  
  801.     40..49:    Wood
  802.         Render the object as if it were carved out of wood.  The
  803.         wood texture chosen depends on the texture number: texture
  804.         20 uses the first wood defined, texture 21 uses the second
  805.         wood defined, etc.
  806.  
  807.     50..59:    Checkered
  808.         Color the surface of the object according the the chosen
  809.         checkerboard texture.  Texture 50 uses the first defined
  810.         checker pattern, etc.
  811.  
  812.     60..69:    Fractal
  813.         This isn't a texture per se (in so far as most other textures
  814.         operate by changing the color of surface points of the object).
  815.         This texture determines what fractal surface contours should
  816.         be applied to this object.  This texture type may only be
  817.         specified for object type X (fractal objects).  Texture 60
  818.         uses the first defined fractal type, etc.
  819.  
  820.     70..79:    Smooth blend
  821.         Render the surface of the object as a blend between the
  822.         objects normal diffuse color, and the specified blend texture
  823.         color.  Texture 70 uses the first defined blend texture, etc.
  824.  
  825.     80..89:    Snow
  826.         Color the surface of the object by applying the chosen snowfall
  827.         texture.  Texture 80 uses the first defined snow texture, etc.
  828.  
  829.     FUZZ is a pseudo-texture factor 0 to 1 that applies a random fuzz to
  830.     the surface of the object.  This can be used in a number of ways: to
  831.     model soft surfaces like tennis balls; to form imperfectly reflecting
  832.     mirrors, to form translucent (etched) glass, etc.
  833.  
  834.     MIRROR is a 0 to 1 value where 0 means no specular and mirror
  835.     reflection, and 1 means 100% specular & mirror reflection.
  836.  
  837.     IDX is the index of refraction for the object.  This is only relevant if
  838.     the transparency for the object is non-zero.
  839.  
  840.     TRA_B, _G, _R is the transparency of the object in each color band.
  841.     0 means opaque, 1 means 100% transparent.
  842.  
  843.     AMB_B, _G, _R is the ambient light value for the object, 0 to 1.  0
  844.     means no pseudo-ambient light, 1 means VERY strong ambient light
  845.     (generally not useful so strong -- washes the object out).
  846.  
  847.     DIF_B, _G, _R is the diffuse reflection values 0 to 1 for the object
  848.     in the color bands.  For example, glass has virtually zero diffuse
  849.     reflection, while chaulk has very high (near 1) diffuse reflection.
  850.     The diffuse coefficients determine the color of the object (in conjunction
  851.     with the color of the light sources).
  852.  
  853. From the above, notice that non-rational objects can be created.  For
  854. example, a ball that is 100% transparent AND 100% reflective.
  855.  
  856. Now onto each object.  The parameters below FOLLOW (appear to the right
  857. of) all of the above property parameters.
  858.  
  859. s CENTERX CENTERY CENTERZ  RADIUS
  860.     Sphere.  Self-explanetory.
  861.  
  862. q POSX POSY POSZ  VE_X VE_Y VE_Z  VP_X VP_Y VP_Z
  863.     Parallelogram.
  864.     The position triple defines a corner of the parallelogram.  The
  865.     second and third triple are two vectors that define the two sides of
  866.     the object adjacent to and relative to the defining point.  Here's
  867.     the hard part: the order of the two vectors matters.  To try to put
  868.     it simply, the VE vector is the one on the left when viewed from
  869.     "above," and the VP vector is the one on the right.  In another way,
  870.     the VP vector is clockwise from the VE vector.  If the two vectors
  871.     are reversed, the object will appear invisble.  So you may have to
  872.     experiment by reversing them.  Note that the two vectors do not have
  873.     to be orthogonal.
  874.  
  875. t POSX POSY POSZ  VE_X VE_Y VE_Z  VP_X VP_Y VP_Z
  876.     Triangle.
  877.     Same as for a parallelegram, except that the VE, VP vectors define
  878.     the two sides of the triangle.
  879.  
  880. x POSX POSY POSZ  POS1X POS1Y POS1Z  POS2X POS2Y POS2Z
  881.     Fractal.
  882.     This is very much like a triangle, except that whereas the second and
  883.     third set of XYZ values for triangles are relative to the base position
  884.     of the triangle, for a fractal object all three XYZ triples are absolute
  885.     object space positions.
  886.  
  887. r CENTERX CENTERY CENTERZ VE_X VE_Y VE_Z  VP_X VP_Y VP_Z  MINRAD MAXRAD
  888.     Ring (or annullus).
  889.     Rings are sort of like parallelograms.  The first triple defines the
  890.     center of the ring.  The VE and VP triples radiate from that point
  891.     and define the plane of the ring.  It is undefined as to what
  892.     happens if the two vectors are not orthogonal.  MINRAD is the inside
  893.     radius of the ring (which may be zero, forming a disk); MAXRAD is
  894.     the outside radius of the ring.
  895.  
  896. The { and } command lines may be placed around any arbitrary set of
  897. object command lines.  This allows RENDER to do optimized ray tracing by
  898. calculating extent spheres around the indicated primitive objects and
  899. then checking ray intersections with the extent sphere rather than
  900. one-by-one with all the inner objects.  Extents may be nested.
  901.  
  902.  Source file information
  903.  ~~~~~~ ~~~~ ~~~~~~~~~~~
  904. Each program is kept in its own source file directory:
  905.  
  906.     ray_source/
  907.         makefile
  908.         ray.h    - all global definitaions
  909.         ray.c    - main module of ray tracer
  910.         val.c    - current intensity value of an object
  911.         hit.c    - calculate if an object gets hit by a ray
  912.         tex.c    - calculate the texture of an object
  913.         ext.c    - handle extents ({,} commands)
  914.         rnd.c    - random number table
  915.         mth.c    - perform vector and matrix math
  916.         fil.c    - file i/o
  917.         int.c    - find intersections with objects
  918.         cal.c    - top level object calculations
  919.     ray2_source/
  920.         makefile
  921.         ray2.c    - source for post-processor
  922.     display_source/
  923.         makefile
  924.         display.c - source for display package
  925.  
  926.